package main

import (
	"amazegame/config"
	"amazegame/core"
	"amazegame/log"
	"flag"
	"fmt"
)

type RegCenterConfig struct {
	ClusterConf core.ClusterConf
	LogConf     log.Conf
}

type ListenWatch struct {
}

func (*ListenWatch) OnNodeChange(nodes []*core.Node) {
	for i := 0; i < len(nodes); i++ {
		fmt.Printf("OnNodeChange() name:%s id:%d bindaddr:%s\n", nodes[i].Name, nodes[i].Id, nodes[i].BindAddr)
	}
}
func main() {
	var cfgFile = flag.String("c", "", "cluster config file.")
	var nodeName = flag.String("n", "", "node name.")
	var bindAddr = flag.String("b", "", "bind address. ip:port ")
	flag.Parse()
	var conf RegCenterConfig
	var err error
	if *cfgFile != "" {
		err = config.Load(*cfgFile, &conf)
		if err != nil {
			fmt.Println("can not load config file")
			return
		}
	}
	//log
	_, _ = log.NewLog(&conf.LogConf)

	callbackContext := &ListenWatch{}
	adapter, _ := core.NewAdapter(&conf.ClusterConf)
	adapter.Register(*nodeName, *bindAddr, callbackContext)
	//adapter.Register("abc", "127.0.0.1:2020",)
	//	err = adapter.Connect(conf)
	//	core.NewNode(adapter, "abc", "127.0.0.1:2020")
	//} else {
	//	conf = core.DefaultConf()
	//}

}
